package tech.runchen.gz5055.oms.modules.system.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import tech.runchen.gz5055.oms.common.annotation.RequiresPermissions;
import tech.runchen.gz5055.oms.common.annotation.SysLog;
import tech.runchen.gz5055.oms.common.base.AbstractController;
import tech.runchen.gz5055.oms.common.enums.BusinessType;
import tech.runchen.gz5055.oms.common.enums.UserType;
import tech.runchen.gz5055.oms.common.utils.PageInfo;
import tech.runchen.gz5055.oms.common.utils.Result;
import tech.runchen.gz5055.oms.modules.system.entity.SysLogininforEntity;
import tech.runchen.gz5055.oms.modules.system.service.ISysLogininforService;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zzj
 * @since 2023-03-07
 */
@Api(tags = "管理平台 - 登录日志")
@RestController
@RequestMapping("/sys/logininfor")
public class SysLogininforController extends AbstractController {

    @Autowired
    private ISysLogininforService logininforService;

    @ApiOperation("登录日志列表")
    @RequiresPermissions()
    @GetMapping("/list")
    public Result list(@RequestParam Map<String, Object> params) {
        PageInfo page = logininforService.queryPage(params);
        return Result.success(page);
    }

    @ApiOperation("选择登录日志")
    @RequiresPermissions()
    @GetMapping("/select")
    public Result select(@RequestParam Map<String, Object> params) {
        List<SysLogininforEntity> list = logininforService.querySelect(params);
        return Result.success(list);
    }

    @ApiOperation("登录日志详情")
    @RequiresPermissions()
    @GetMapping("/{sysLogId}")
    public Result info(@PathVariable("sysLogId") Long sysLogId) {
        SysLogininforEntity logininfor = logininforService.getById(sysLogId);
        return Result.success(logininfor);
    }

    @ApiOperation("保存设备信息")
    @RequiresPermissions()
    @PostMapping("/save")
    public Result save(@Validated @RequestBody SysLogininforEntity logininfor) {
        logininforService.saveLogininfor(logininfor);
        return Result.success();
    }

    @ApiOperation("更新登录日志信息")
    @RequiresPermissions()
    @PostMapping("/update")
    public Result update(@Validated @RequestBody SysLogininforEntity logininfor) {
        logininforService.updateLogininfor(logininfor);
        return Result.success();
    }

    @SysLog(title = "删除登录日志", businessType = BusinessType.DELETE)
    @RequiresPermissions()
    @ApiOperation("删除登录日志信息")
    @PostMapping("/delete")
    public Result delete(@RequestBody Long[] sysLogIds) {
        logininforService.deleteBatch(sysLogIds);
        return Result.success();
    }
}
